package com.city.service.pub.impl;

import com.city.domain.pub.PubUser;
import com.city.repository.pub.PubUserRepository;
import com.city.service.pub.PubUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.annotation.Resources;
import java.util.List;

/**
 * @deprecation:基本用户信息表
 * @dmail: 398521613@qq.com
 * @author: L-H
 * @date: 2018-07-18 13:14
 */
@Service("pubUserServiceImpl")
public class PubUserServiceImpl implements PubUserService {


    @Autowired
    private PubUserRepository userRepository2; //用于查询limit的数据

    @Resource
    private PubUserRepository userRepository;

    @Resource
    private PubUserRedisServiceImpl pubUserRedisService;


    @Cacheable(value="userCache")
    @Override
    public List<PubUser> findAll() {
        return userRepository.findAll();
    }

    @Cacheable(value="userCache")
    @Override
    public List<PubUser> findAllByLimit(Integer left,Integer right){
        return userRepository.findAllByIdLimit(left,right);
    }


    @Override
    public List<PubUser> findAllByLimit2(Integer left,Integer right){
        return userRepository2.findAllByIdLimit2((left-1)*right,right);
    }

    @Override
    public long countfindAllByLimit2(){
        return userRepository2.countfindAllByIdLimit2();
    }

    @Override
    public List<PubUser> findFamilyMenberByHouseholdId(Integer householdId){
        return userRepository2.findFamilyMenberByHouseholdId(householdId);
    }

    @Override
    public List<String> findFamilyMenberNameByHouseholdId(Integer householdId){
        return userRepository2.findFamilyMenberNameByHouseholdId(householdId);
    }

    @Override
    public List<PubUser> getUserByNameTelIdcard(String keyword,Integer page,Integer num){
        return userRepository2.seachUser("%"+keyword+"%",(page-1)*num,num);
    }

    @Override
    public long countBynameTelIdcard(String keyword) {
        return userRepository2.seachUserAll("%"+keyword+"%");
    }

    @Cacheable(value="userCache")
    @Override
    public PubUser getUserByTell(String tell) {
        return userRepository.getUserByTell(tell);
    }

    @Cacheable(value="userCache")
    @Override
    public PubUser getUserByIdCard(String idCard) {
        return userRepository.getUserByIdCard(idCard);
    }

    @Cacheable(value="userCache")
    @Override
    public PubUser getUserByTellAndName(String name, String tellphone) {
        return userRepository.getUserByTellAndName(name, tellphone);
    }


    @Override
    public PubUser findById(int id) {
        return userRepository.findOne(id);
    }

    @Override
    public PubUser saveUser(PubUser user) {
        return userRepository.save(user);
    }

    @Override
    public List<PubUser> findByAuthLimit(Integer page, Integer limit) {
        return userRepository.findByAuthLimit((page-1)*limit,limit);
    }

    @Override
    public long count() {
        return userRepository.count();
    }

    /**
     * @Author: 李顺时
     * @Description: 通过name来查询用户  gis以房找人
     * @Date: 17:06 2018/8/24
     */
    @Override
    public List<PubUser> getUserByName(String keyword){
        return userRepository2.seachUserByName(keyword);
    }

    @Override
    public PubUser findByIdCardAndId(String idCard, int id) {
        return userRepository.findByIdCardAndId(idCard, id);
    }

    @Override
    public List<PubUser> findByBranchId(Integer branchId) {
        return userRepository.findByBranchId(branchId);
    }


}
